package com.ky.course.controller;


import cn.hutool.core.convert.NumberWithFormat;
import com.ky.common.config.SystemConfig;
import com.ky.common.param.FeedbackAdd;
import com.ky.common.util.JwtUtil;
import com.ky.common.vo.R;
import com.ky.course.service.OpenCourseVideoComplaintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zpa
 * @since 2024-06-21
 */
@RestController
@RequestMapping("/course/open-course-video-complaint")
public class OpenCourseVideoComplaintController {

    @Autowired
    private OpenCourseVideoComplaintService openCourseVideoComplaintService;


    @PostMapping("/feedback")
    public R insertFeedback(HttpServletRequest request, @RequestBody FeedbackAdd feedbackAdd){
        String token = request.getHeader(SystemConfig.HEADER_TOKEN);
        if(token==null){
            return R.fail("用户未登录");
        }
        // 使用JWT解析token
        if(feedbackAdd==null){
            return R.fail("参数错误");
        }
        Integer id = ((NumberWithFormat) JwtUtil.parseToken(token, "id")).intValue();
        if (id==null){
            return R.fail("不正确的token");
        }
        return openCourseVideoComplaintService.insertFeedback( id,feedbackAdd);
    };


}

